<?php

namespace App\Models\Traits;

trait Btn
{


    // 这是label 标签
    public function btn(string $route, $type, $name, $icon = null) // {{ route('admin.user.restore',$item) }}\
    {
        $info = session('admin_routes');
        if ($info !== true && $info != null) {
            $nodes = array_merge(array_filter($info), config('rbac.allow_route'));
            if (in_array($route, $nodes)) {
                return "<a href=" . route($route, $this) . " class='{$type} radius'><i class=\"Hui-iconfont\">{$name}</i></a>";
            } else {
                return '';
            }
        } else {
            return "<a href=" . route($route, $this) . " class='{$type} radius' ><i class=\"Hui-iconfont\">{$icon}</i>{$name}</a>";
        }
    }

    // 这是label 标签----专为删除设计
    public function dbtn(string $route, $type, $name, $icon = null) // {{ route('admin.user.restore',$item) }}\
    {
        $info = session('admin_routes');
        if ($info !== true) {
            $nodes = array_merge(array_filter($info), config('rbac.allow_route'));
            if (in_array($route, $nodes)) {
                return "<form action = " . route($route, $this) . " method = \"post\">
<input class = '{$type}' type = 'submit' value = '{$name}' />
@method('delete')
<i class=\"Hui - iconfont\">{$icon}</i>
@csrf
</form>";
            } else {
                return '';
            }
        } else {
            return "<form action = " . route($route, $this) . " method = \"post\">
<input class='btn btn-danger radius' type = \"submit\" value = '{$name}' />
<i class=\"Hui - iconfont\">{$icon}</i>
<input type=\"hidden\" name=\"_method\" value=\"delete\" />
<input type=\"hidden\" name=\"_token\" value='{{ csrf_token() }}'>
</form>";
        }
    }


    // 修改
    public function editBtn(string $route)
    {
        return $this->btn($route, 'label-success label', '修改');
    }

    // 删除
    public function delBtn(string $route)
    {
        return $this->btn($route, 'label label-danger', '删0除');
    }

    // 恢复
    public function restoreBtn(string $route)
    {
        return $this->btn($route, 'label label-error', '恢复');
    }

    // 角色分配
    public function roleBtn(string $route)
    {
        return $this->btn($route, 'label label-warning', '角色分配');
    }

    // 批量删除
    public function delAllBtn(string $route)
    {
        return $this->btn($route, 'label label-danger', '批量删除') ? true : false;
    }

    // 角色分配
    public function addBtn(string $route)
    {
        return $this->btn($route, 'btn btn-primary', '添加', '&#xe600;');
    }

    // 权限
    public function nodeBtn(string $route)
    {
        return $this->btn($route, 'label label-success', '权限');
    }
}
